
package com.fulihui.wgj.consumer.config;


import com.fulihui.common.util.*;
import com.fulihui.wgj.consumer.config.property.JedisPoolProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @author: LiuJie
 * @date: 2018-07-05 17:14
 */
@Configuration
public class RedisConfig {

    @Autowired
    JedisPoolProperties jedisPoolProperties;

    public JedisPoolConfig jedisPoolConfig() {
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        poolConfig.setMaxIdle(jedisPoolProperties.getMaxidle());
        poolConfig.setMaxTotal(jedisPoolProperties.getMaxtotal());
        return poolConfig;
    }

    public JedisPool jedisPool() {
        return new JedisPool(jedisPoolConfig(), jedisPoolProperties.getHost(),
                jedisPoolProperties.getPort(), jedisPoolProperties.getTimeout(),
                jedisPoolProperties.getPassword(), jedisPoolProperties.getDatabase());
    }

    @Bean
    public JedisUtil jedisUtil() {
        JedisUtil jedisUtil = new JedisUtil();
        jedisUtil.setJedisPool(jedisPool());
        return jedisUtil;
    }

    // *********************** 以下是利用 jedis 封装的各种主题的工具类 **********************

    @Bean
    public PlatformUtil platformUtil(JedisUtil jedisUtil) {
        PlatformUtil platformUtil = new PlatformUtil();
        platformUtil.setJedisUtil(jedisUtil);
        return platformUtil;
    }

    @Bean
    public TenMinutesMsgUtil tenMinutesMsgUtil(JedisUtil jedisUtil){
        return new TenMinutesMsgUtil(jedisUtil);
    }

    @Bean
    public SevenRemainingUtil sevenRemainingUtil(JedisUtil jedisUtil){
        return new SevenRemainingUtil(jedisUtil);
    }

    @Bean
    public TemplateDisabledUtil templateDisabledUtil(JedisUtil jedisUtil){
        return new TemplateDisabledUtil(jedisUtil);
    }
    
    @Bean
    public TemplateMsgCancelUtil templateMsgCancelUtil(JedisUtil jedisUtil){
        return new TemplateMsgCancelUtil(jedisUtil);
    }

    @Bean
    public MassMsgIdUtil massMsgIdUtil(JedisUtil jedisUtil){
        return  new MassMsgIdUtil(jedisUtil);
    }

}
